Skip to main content

App Context and Settings

Corva wraps a frontend app in an app context. Use useAppCommons from @corva/ui/effects to read supported app metadata, selected assets, user context, and settings from any component inside the app.

import { useAppCommons } from '@corva/ui/effects';

export function AssetSummary() {
const { appName, well, rig, fracFleet } = useAppCommons();

return (
<section>
<h2>{appName}</h2>
<p>{well?.name ?? rig?.name ?? fracFleet?.name ?? 'No asset selected'}</p>
</section>
);
}

This is preferable to passing the entire root app-props object through several component layers.

Supported context

The public useAppCommons value includes:

ValuePurpose
app, appId, appKey, appNameCurrent app instance and identity
appSettingsSaved settings for this app instance
onSettingChangeUpdate one setting by key
onSettingsChangeUpdate several settings together
well, rigDrilling assets and single-well context
fracFleet, wellsCompletion fleet and multi-well context
currentUserSigned-in user, when available
dashboardMetaOptional dashboard capabilities such as multi-well or chipless mode
maximizedWhether the app is currently maximized

Some values are optional because the app can render before an asset is selected or in more than one dashboard layout. Always handle missing assets explicitly.

Drilling and completion context

const { rig, well } = useAppCommons(); // drilling
const { fracFleet, well, wells = [] } = useAppCommons(); // completion

For completion apps, an asset-scoped dashboard can supply well, while a general or multi-well dashboard can supply wells. Normalize those two cases before querying data.

Persist one setting

onSettingChange saves a value under one settings key:

import { Switch } from '@corva/ui/componentsV2';
import { useAppCommons } from '@corva/ui/effects';

export function ShowPlanControl() {
const { appSettings = {}, onSettingChange } = useAppCommons();

return (
<Switch
checked={Boolean(appSettings.showPlan)}
onLabel="Show plan"
onChange={checked => onSettingChange('showPlan', checked)}
/>
);
}

Use onSettingsChange when several values form one customer action:

onSettingsChange({
...appSettings,
rangeStart: nextStart,
rangeEnd: nextEnd,
});

Build the settings panel

The generated AppSettings component receives settings, onSettingChange, and onSettingsChange. With App Header V3 enabled, Corva displays this component from the settings action in AppHeader.

import { Checkbox, FormControlLabel } from '@material-ui/core';

export default function AppSettings({ settings, onSettingChange }) {
return (
<FormControlLabel
label="Show plan"
control={
<Checkbox
checked={Boolean(settings.showPlan)}
onChange={event => onSettingChange('showPlan', event.target.checked)}
/>
}
/>
);
}

Keep defaults in a shared constants file and merge them with saved values, as the generated starter does. That keeps a newly installed app usable before any settings have been saved.

What belongs in settings?

Persist settings when they are customer choices that should survive a reload, such as:

  • Curves or series to show.
  • Thresholds and display units.
  • A default time or depth range.
  • Completion pad-mode selections.

Keep transient interface state inside React state, such as:

  • Whether a tooltip or temporary dialog is open.
  • Hovered rows.
  • In-progress form text that has not been applied.
Context ownership

AppContainer and AppHeader also consume this context. Use their supported props for customization rather than rebuilding the app header or copying platform context into a second provider.